package adapter.power;

import java.util.ArrayList;
import java.util.List;

public class Main {

	public static void main(String[] args) {
		List<DC5Adapter> list = new ArrayList<>();

		list.add(new ChinaPowerAdapter());
		list.add(new JapanPowerAdapter());

		// 中国
		AC ac220 = new AC220();
		try {
			DC5Adapter c = getPowerAdapter(list, ac220);
			c.outputDC5V(ac220);
		} catch (Exception e) {
			e.printStackTrace();
		}

		// 日本
		AC ac110 = new AC110();
		try {
			DC5Adapter j = getPowerAdapter(list, ac110);
			j.outputDC5V(ac110);
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	public static DC5Adapter getPowerAdapter(List<DC5Adapter> list, AC ac) throws Exception {
		DC5Adapter r = null;
		for (DC5Adapter dc : list) {
			if (dc.support(ac)) {
				r = dc;
				break;
			}
		}

		if (r == null) {
			throw new Exception("没有找到合适的电源适配器");
		}

		return r;
	}
}
